package com.br.sae.model.dao;

import java.util.List;

import javax.persistence.Query;

import com.br.sae.conexaobd.SistemaDAO;
import com.br.sae.model.entitys.Professor;

public class ProfessorBD {

	public List<Professor> consultaProfessores() {
		Query query = SistemaDAO.createNamedQuery("ProfessorBy");
		return query.getResultList();
	}

	public List<Professor> consultaProfessor(String nome) {
		String sql = "SELECT professor FROM Professor professor WHERE professor.nome= :nome";
		Query query = SistemaDAO.createQuery(sql);
		query.setParameter("nome", nome);
		return query.getResultList();
	}

	
	public boolean incluirProfessor(Professor professor) {
		try {
			SistemaDAO.persistProfessor(professor);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public boolean alterarProfessor(Professor professor) {
		try {
			SistemaDAO.updateProfessor(professor);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public boolean removerProfessor(Professor professor) {
		try {
			SistemaDAO.removerProfessor(professor);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

}
